package com.share.sharelibrary.share;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.view.View;

import com.share.sharelibrary.BR;
import com.share.sharelibrary.MultiTypeAdapter;
import com.share.sharelibrary.R;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.shareboard.SnsPlatform;

/**
 * @author QiQi
 * @date 2017/5/12
 * @description 分享面板Item
 */

public class ShareItem implements MultiTypeAdapter.IItem {

    private SnsPlatform snsPlatform;

    private OnShareItemClickListener onShareItemClickListener;

    private Context context;


    public ShareItem(Context context, SnsPlatform snsPlatform) {
        this.context = context;
        this.snsPlatform = snsPlatform;
    }

    public void setOnShareItemClickListener(OnShareItemClickListener onShareItemClickListener) {
        this.onShareItemClickListener = onShareItemClickListener;
    }

    public void onItemClicked(View view) {
        if (onShareItemClickListener != null) {
            onShareItemClickListener.onClick(ShareItem.this.snsPlatform.mPlatform);
        }
    }

    public CharSequence getShareKey() {
//        try {
//            Field field = R.string.class.getField(snsPlatform.mShowWord);
//            int i = field.getInt(new R.string());
//            return context.getString(i);
//        } catch (NoSuchFieldException | IllegalAccessException e) {
//            e.printStackTrace();
//        }
        return snsPlatform.mShowWord;
    }


    public Drawable getUrl() {
        ApplicationInfo appinfo = context.getApplicationInfo();
        int i = context.getResources().getIdentifier(snsPlatform.mGrayIcon, "drawable", appinfo.packageName);
        return ContextCompat.getDrawable(context, i);

    }


    @Override
    public int getLayout() {
        return R.layout.item_share_layout;
    }

    @Override
    public int getVariableId() {
        return BR.item;
    }

    public interface OnShareItemClickListener {
        void onClick(SHARE_MEDIA platform);
    }
}
